home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
utility.lha
/
utility
/
statcount.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-08
|
795b
|
43 lines
// $Id: statcount.C,v 1.1 91/09/06 12:06:34 dag Exp $
#include <statcount.H>
#include <stdio.h>
#include <strings.h>
StatCount :: StatCount(const char* s, int mini, int maxi, unsigned reso)
: min(mini), res(reso), n((maxi - mini)/res), v(new unsigned[n])
{
if (s == 0) s = "";
title = new char[strlen(s) + 1];
strcpy(title, s);
for (int i = 0; i < n; i++)
v[i] = 0;
}
void StatCount :: operator () (int x)
{
register int i = (x - min) / res;
if (i < 0) i = 0;
if (i >= n) i = n-1;
v[i]++;
}
void StatCount :: Dump() const
{
fprintf(stderr, "%s\n", title);
for (int i = 0; i < n; i++) {
int start = i*res + min;
fprintf(stderr, "%d-%d\t%u\n", start, start+res-1, v[i]);
}
}
StatCount :: ~StatCount()
{
Dump();
delete [] title;
delete [] v;
}